home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / controls / SWFLoader.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  43.2 KB  |  1,323 lines

  1. package mx.controls
  2. {
  3.    import flash.display.Bitmap;
  4.    import flash.display.DisplayObject;
  5.    import flash.display.DisplayObjectContainer;
  6.    import flash.display.Loader;
  7.    import flash.display.LoaderInfo;
  8.    import flash.display.Sprite;
  9.    import flash.events.Event;
  10.    import flash.events.EventDispatcher;
  11.    import flash.events.HTTPStatusEvent;
  12.    import flash.events.IEventDispatcher;
  13.    import flash.events.IOErrorEvent;
  14.    import flash.events.ProgressEvent;
  15.    import flash.events.SecurityErrorEvent;
  16.    import flash.geom.Point;
  17.    import flash.geom.Rectangle;
  18.    import flash.net.URLRequest;
  19.    import flash.system.ApplicationDomain;
  20.    import flash.system.Capabilities;
  21.    import flash.system.LoaderContext;
  22.    import flash.system.SecurityDomain;
  23.    import flash.utils.ByteArray;
  24.    import mx.core.Application;
  25.    import mx.core.FlexLoader;
  26.    import mx.core.FlexVersion;
  27.    import mx.core.IFlexDisplayObject;
  28.    import mx.core.ISWFLoader;
  29.    import mx.core.IUIComponent;
  30.    import mx.core.UIComponent;
  31.    import mx.core.mx_internal;
  32.    import mx.events.FlexEvent;
  33.    import mx.events.InterManagerRequest;
  34.    import mx.events.InvalidateRequestData;
  35.    import mx.events.SWFBridgeEvent;
  36.    import mx.events.SWFBridgeRequest;
  37.    import mx.managers.CursorManager;
  38.    import mx.managers.ISystemManager;
  39.    import mx.managers.SystemManagerGlobals;
  40.    import mx.styles.ISimpleStyleClient;
  41.    import mx.utils.LoaderUtil;
  42.    
  43.    use namespace mx_internal;
  44.    
  45.    public class SWFLoader extends UIComponent implements ISWFLoader
  46.    {
  47.       mx_internal static const VERSION:String = "3.2.0.3958";
  48.       
  49.       private var _loadForCompatibility:Boolean = false;
  50.       
  51.       private var _loaderContext:LoaderContext;
  52.       
  53.       private var requestedURL:URLRequest;
  54.       
  55.       private var _swfBridge:IEventDispatcher;
  56.       
  57.       private var _bytesTotal:Number = NaN;
  58.       
  59.       private var useUnloadAndStop:Boolean;
  60.       
  61.       private var flexContent:Boolean = false;
  62.       
  63.       private var explicitLoaderContext:Boolean = false;
  64.       
  65.       private var resizableContent:Boolean = false;
  66.       
  67.       private var brokenImageBorder:IFlexDisplayObject;
  68.       
  69.       private var _maintainAspectRatio:Boolean = true;
  70.       
  71.       private var _source:Object;
  72.       
  73.       private var mouseShield:Sprite;
  74.       
  75.       private var contentRequestID:String = null;
  76.       
  77.       mx_internal var contentHolder:DisplayObject;
  78.       
  79.       private var brokenImage:Boolean = false;
  80.       
  81.       private var _bytesLoaded:Number = NaN;
  82.       
  83.       private var _autoLoad:Boolean = true;
  84.       
  85.       private var _showBusyCursor:Boolean = false;
  86.       
  87.       private var _scaleContent:Boolean = true;
  88.       
  89.       private var isContentLoaded:Boolean = false;
  90.       
  91.       private var unloadAndStopGC:Boolean;
  92.       
  93.       private var _trustContent:Boolean = false;
  94.       
  95.       private var attemptingChildAppDomain:Boolean = false;
  96.       
  97.       private var scaleContentChanged:Boolean = false;
  98.       
  99.       private var contentChanged:Boolean = false;
  100.       
  101.       public function SWFLoader()
  102.       {
  103.          super();
  104.          tabChildren = true;
  105.          tabEnabled = false;
  106.          addEventListener(FlexEvent.INITIALIZE,initializeHandler);
  107.          addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
  108.          showInAutomationHierarchy = false;
  109.       }
  110.       
  111.       public function get contentHeight() : Number
  112.       {
  113.          return !!mx_internal::contentHolder ? mx_internal::contentHolder.height : NaN;
  114.       }
  115.       
  116.       [Bindable("trustContentChanged")]
  117.       public function get trustContent() : Boolean
  118.       {
  119.          return _trustContent;
  120.       }
  121.       
  122.       public function set trustContent(param1:Boolean) : void
  123.       {
  124.          if(_trustContent != param1)
  125.          {
  126.             _trustContent = param1;
  127.             invalidateProperties();
  128.             invalidateSize();
  129.             invalidateDisplayList();
  130.             dispatchEvent(new Event("trustContentChanged"));
  131.          }
  132.       }
  133.       
  134.       [Bindable("maintainAspectRatioChanged")]
  135.       public function get maintainAspectRatio() : Boolean
  136.       {
  137.          return _maintainAspectRatio;
  138.       }
  139.       
  140.       private function unScaleContent() : void
  141.       {
  142.          mx_internal::contentHolder.scaleX = 1;
  143.          mx_internal::contentHolder.scaleY = 1;
  144.          mx_internal::contentHolder.x = 0;
  145.          mx_internal::contentHolder.y = 0;
  146.       }
  147.       
  148.       public function set maintainAspectRatio(param1:Boolean) : void
  149.       {
  150.          _maintainAspectRatio = param1;
  151.          dispatchEvent(new Event("maintainAspectRatioChanged"));
  152.       }
  153.       
  154.       override public function regenerateStyleCache(param1:Boolean) : void
  155.       {
  156.          var sm:ISystemManager = null;
  157.          var recursive:Boolean = param1;
  158.          super.regenerateStyleCache(recursive);
  159.          try
  160.          {
  161.             sm = content as ISystemManager;
  162.             if(sm != null)
  163.             {
  164.                Object(sm).regenerateStyleCache(recursive);
  165.             }
  166.          }
  167.          catch(error:Error)
  168.          {
  169.          }
  170.       }
  171.       
  172.       private function get contentHolderHeight() : Number
  173.       {
  174.          var loaderInfo:LoaderInfo = null;
  175.          var content:IFlexDisplayObject = null;
  176.          var bridge:IEventDispatcher = null;
  177.          var request:SWFBridgeRequest = null;
  178.          var testContent:DisplayObject = null;
  179.          if(mx_internal::contentHolder is Loader)
  180.          {
  181.             loaderInfo = Loader(mx_internal::contentHolder).contentLoaderInfo;
  182.          }
  183.          if(loaderInfo)
  184.          {
  185.             if(loaderInfo.contentType == "application/x-shockwave-flash")
  186.             {
  187.                try
  188.                {
  189.                   if(systemManager.swfBridgeGroup)
  190.                   {
  191.                      bridge = swfBridge;
  192.                      if(bridge)
  193.                      {
  194.                         request = new SWFBridgeRequest(SWFBridgeRequest.GET_SIZE_REQUEST);
  195.                         bridge.dispatchEvent(request);
  196.                         return request.data.height;
  197.                      }
  198.                   }
  199.                   content = Loader(mx_internal::contentHolder).content as IFlexDisplayObject;
  200.                   if(content)
  201.                   {
  202.                      return content.measuredHeight;
  203.                   }
  204.                }
  205.                catch(error:Error)
  206.                {
  207.                   return mx_internal::contentHolder.height;
  208.                }
  209.             }
  210.             else
  211.             {
  212.                try
  213.                {
  214.                   testContent = Loader(mx_internal::contentHolder).content;
  215.                }
  216.                catch(error:Error)
  217.                {
  218.                   return mx_internal::contentHolder.height;
  219.                }
  220.             }
  221.             return loaderInfo.height;
  222.          }
  223.          if(mx_internal::contentHolder is IUIComponent)
  224.          {
  225.             return IUIComponent(mx_internal::contentHolder).getExplicitOrMeasuredHeight();
  226.          }
  227.          if(mx_internal::contentHolder is IFlexDisplayObject)
  228.          {
  229.             return IFlexDisplayObject(mx_internal::contentHolder).measuredHeight;
  230.          }
  231.          return mx_internal::contentHolder.height;
  232.       }
  233.       
  234.       [Bindable("loaderContextChanged")]
  235.       public function get loaderContext() : LoaderContext
  236.       {
  237.          return _loaderContext;
  238.       }
  239.       
  240.       public function set showBusyCursor(param1:Boolean) : void
  241.       {
  242.          if(_showBusyCursor != param1)
  243.          {
  244.             _showBusyCursor = param1;
  245.             if(_showBusyCursor)
  246.             {
  247.                CursorManager.mx_internal::registerToUseBusyCursor(this);
  248.             }
  249.             else
  250.             {
  251.                CursorManager.mx_internal::unRegisterToUseBusyCursor(this);
  252.             }
  253.          }
  254.       }
  255.       
  256.       override public function notifyStyleChangeInChildren(param1:String, param2:Boolean) : void
  257.       {
  258.          var sm:ISystemManager = null;
  259.          var styleProp:String = param1;
  260.          var recursive:Boolean = param2;
  261.          super.notifyStyleChangeInChildren(styleProp,recursive);
  262.          try
  263.          {
  264.             sm = content as ISystemManager;
  265.             if(sm != null)
  266.             {
  267.                Object(sm).notifyStyleChangeInChildren(styleProp,recursive);
  268.             }
  269.          }
  270.          catch(error:Error)
  271.          {
  272.          }
  273.       }
  274.       
  275.       private function getHorizontalAlignValue() : Number
  276.       {
  277.          var _loc1_:String = getStyle("horizontalAlign");
  278.          if(_loc1_ == "left")
  279.          {
  280.             return 0;
  281.          }
  282.          if(_loc1_ == "right")
  283.          {
  284.             return 1;
  285.          }
  286.          return 0.5;
  287.       }
  288.       
  289.       [Bindable("sourceChanged")]
  290.       public function get source() : Object
  291.       {
  292.          return _source;
  293.       }
  294.       
  295.       [Bindable("loadForCompatibilityChanged")]
  296.       public function get loadForCompatibility() : Boolean
  297.       {
  298.          return _loadForCompatibility;
  299.       }
  300.       
  301.       private function contentLoaderInfo_httpStatusEventHandler(param1:HTTPStatusEvent) : void
  302.       {
  303.          dispatchEvent(param1);
  304.       }
  305.       
  306.       [Bindable("autoLoadChanged")]
  307.       public function get autoLoad() : Boolean
  308.       {
  309.          return _autoLoad;
  310.       }
  311.       
  312.       public function set source(param1:Object) : void
  313.       {
  314.          if(_source != param1)
  315.          {
  316.             _source = param1;
  317.             contentChanged = true;
  318.             invalidateProperties();
  319.             invalidateSize();
  320.             invalidateDisplayList();
  321.             dispatchEvent(new Event("sourceChanged"));
  322.          }
  323.       }
  324.       
  325.       public function set loaderContext(param1:LoaderContext) : void
  326.       {
  327.          _loaderContext = param1;
  328.          explicitLoaderContext = true;
  329.          dispatchEvent(new Event("loaderContextChanged"));
  330.       }
  331.       
  332.       private function get contentHolderWidth() : Number
  333.       {
  334.          var loaderInfo:LoaderInfo = null;
  335.          var content:IFlexDisplayObject = null;
  336.          var request:SWFBridgeRequest = null;
  337.          var testContent:DisplayObject = null;
  338.          if(mx_internal::contentHolder is Loader)
  339.          {
  340.             loaderInfo = Loader(mx_internal::contentHolder).contentLoaderInfo;
  341.          }
  342.          if(loaderInfo)
  343.          {
  344.             if(loaderInfo.contentType == "application/x-shockwave-flash")
  345.             {
  346.                try
  347.                {
  348.                   if(swfBridge)
  349.                   {
  350.                      request = new SWFBridgeRequest(SWFBridgeRequest.GET_SIZE_REQUEST);
  351.                      swfBridge.dispatchEvent(request);
  352.                      return request.data.width;
  353.                   }
  354.                   content = Loader(mx_internal::contentHolder).content as IFlexDisplayObject;
  355.                   if(content)
  356.                   {
  357.                      return content.measuredWidth;
  358.                   }
  359.                }
  360.                catch(error:Error)
  361.                {
  362.                   return mx_internal::contentHolder.width;
  363.                }
  364.             }
  365.             else
  366.             {
  367.                try
  368.                {
  369.                   testContent = Loader(mx_internal::contentHolder).content;
  370.                }
  371.                catch(error:Error)
  372.                {
  373.                   return mx_internal::contentHolder.width;
  374.                }
  375.             }
  376.             return loaderInfo.width;
  377.          }
  378.          if(mx_internal::contentHolder is IUIComponent)
  379.          {
  380.             return IUIComponent(mx_internal::contentHolder).getExplicitOrMeasuredWidth();
  381.          }
  382.          if(mx_internal::contentHolder is IFlexDisplayObject)
  383.          {
  384.             return IFlexDisplayObject(mx_internal::contentHolder).measuredWidth;
  385.          }
  386.          return mx_internal::contentHolder.width;
  387.       }
  388.       
  389.       [Bindable("progress")]
  390.       public function get bytesLoaded() : Number
  391.       {
  392.          return _bytesLoaded;
  393.       }
  394.       
  395.       private function removeInitSystemManagerCompleteListener(param1:LoaderInfo) : void
  396.       {
  397.          var _loc2_:EventDispatcher = null;
  398.          if(param1.contentType == "application/x-shockwave-flash")
  399.          {
  400.             _loc2_ = param1.sharedEvents;
  401.             _loc2_.removeEventListener(SWFBridgeEvent.BRIDGE_NEW_APPLICATION,initSystemManagerCompleteEventHandler);
  402.          }
  403.       }
  404.       
  405.       public function set loadForCompatibility(param1:Boolean) : void
  406.       {
  407.          if(_loadForCompatibility != param1)
  408.          {
  409.             _loadForCompatibility = param1;
  410.             contentChanged = true;
  411.             invalidateProperties();
  412.             invalidateSize();
  413.             invalidateDisplayList();
  414.             dispatchEvent(new Event("loadForCompatibilityChanged"));
  415.          }
  416.       }
  417.       
  418.       override protected function measure() : void
  419.       {
  420.          var _loc1_:Number = NaN;
  421.          var _loc2_:Number = NaN;
  422.          super.measure();
  423.          if(isContentLoaded)
  424.          {
  425.             _loc1_ = mx_internal::contentHolder.scaleX;
  426.             _loc2_ = mx_internal::contentHolder.scaleY;
  427.             mx_internal::contentHolder.scaleX = 1;
  428.             mx_internal::contentHolder.scaleY = 1;
  429.             measuredWidth = contentHolderWidth;
  430.             measuredHeight = contentHolderHeight;
  431.             mx_internal::contentHolder.scaleX = _loc1_;
  432.             mx_internal::contentHolder.scaleY = _loc2_;
  433.          }
  434.          else if(!_source || _source == "")
  435.          {
  436.             measuredWidth = 0;
  437.             measuredHeight = 0;
  438.          }
  439.       }
  440.       
  441.       private function contentLoaderInfo_initEventHandler(param1:Event) : void
  442.       {
  443.          dispatchEvent(param1);
  444.          addInitSystemManagerCompleteListener(LoaderInfo(param1.target).loader.contentLoaderInfo);
  445.       }
  446.       
  447.       public function set autoLoad(param1:Boolean) : void
  448.       {
  449.          if(_autoLoad != param1)
  450.          {
  451.             _autoLoad = param1;
  452.             contentChanged = true;
  453.             invalidateProperties();
  454.             invalidateSize();
  455.             invalidateDisplayList();
  456.             dispatchEvent(new Event("autoLoadChanged"));
  457.          }
  458.       }
  459.       
  460.       private function doScaleLoader() : void
  461.       {
  462.          if(!isContentLoaded)
  463.          {
  464.             return;
  465.          }
  466.          unScaleContent();
  467.          var _loc1_:Number = unscaledWidth;
  468.          var _loc2_:Number = unscaledHeight;
  469.          if(contentHolderWidth > _loc1_ || contentHolderHeight > _loc2_ || !parentAllowsChild)
  470.          {
  471.             mx_internal::contentHolder.scrollRect = new Rectangle(0,0,_loc1_,_loc2_);
  472.          }
  473.          else
  474.          {
  475.             mx_internal::contentHolder.scrollRect = null;
  476.          }
  477.          mx_internal::contentHolder.x = (_loc1_ - contentHolderWidth) * getHorizontalAlignValue();
  478.          mx_internal::contentHolder.y = (_loc2_ - contentHolderHeight) * getVerticalAlignValue();
  479.       }
  480.       
  481.       private function getVerticalAlignValue() : Number
  482.       {
  483.          var _loc1_:String = getStyle("verticalAlign");
  484.          if(_loc1_ == "top")
  485.          {
  486.             return 0;
  487.          }
  488.          if(_loc1_ == "bottom")
  489.          {
  490.             return 1;
  491.          }
  492.          return 0.5;
  493.       }
  494.       
  495.       public function get content() : DisplayObject
  496.       {
  497.          if(mx_internal::contentHolder is Loader)
  498.          {
  499.             return Loader(mx_internal::contentHolder).content;
  500.          }
  501.          return mx_internal::contentHolder;
  502.       }
  503.       
  504.       private function dispatchInvalidateRequest(param1:Boolean, param2:Boolean, param3:Boolean) : void
  505.       {
  506.          var _loc4_:ISystemManager = systemManager;
  507.          if(!_loc4_.useSWFBridge())
  508.          {
  509.             return;
  510.          }
  511.          var _loc5_:IEventDispatcher = _loc4_.swfBridgeGroup.parentBridge;
  512.          var _loc6_:uint = 0;
  513.          if(param1)
  514.          {
  515.             _loc6_ |= InvalidateRequestData.PROPERTIES;
  516.          }
  517.          if(param2)
  518.          {
  519.             _loc6_ |= InvalidateRequestData.SIZE;
  520.          }
  521.          if(param3)
  522.          {
  523.             _loc6_ |= InvalidateRequestData.DISPLAY_LIST;
  524.          }
  525.          var _loc7_:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.INVALIDATE_REQUEST,false,false,_loc5_,_loc6_);
  526.          _loc5_.dispatchEvent(_loc7_);
  527.       }
  528.       
  529.       public function getVisibleApplicationRect(param1:Boolean = false) : Rectangle
  530.       {
  531.          var _loc2_:Rectangle = getVisibleRect();
  532.          if(param1)
  533.          {
  534.             _loc2_ = systemManager.getVisibleApplicationRect(_loc2_);
  535.          }
  536.          return _loc2_;
  537.       }
  538.       
  539.       public function unloadAndStop(param1:Boolean = true) : void
  540.       {
  541.          useUnloadAndStop = true;
  542.          unloadAndStopGC = param1;
  543.          source = null;
  544.       }
  545.       
  546.       private function contentLoaderInfo_progressEventHandler(param1:ProgressEvent) : void
  547.       {
  548.          _bytesTotal = param1.bytesTotal;
  549.          _bytesLoaded = param1.bytesLoaded;
  550.          dispatchEvent(param1);
  551.       }
  552.       
  553.       public function get showBusyCursor() : Boolean
  554.       {
  555.          return _showBusyCursor;
  556.       }
  557.       
  558.       override public function get baselinePosition() : Number
  559.       {
  560.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  561.          {
  562.             return 0;
  563.          }
  564.          return super.baselinePosition;
  565.       }
  566.       
  567.       private function initSystemManagerCompleteEventHandler(param1:Event) : void
  568.       {
  569.          var _loc3_:ISystemManager = null;
  570.          var _loc2_:Object = Object(param1);
  571.          if(mx_internal::contentHolder is Loader && _loc2_.data == Loader(mx_internal::contentHolder).contentLoaderInfo.sharedEvents)
  572.          {
  573.             _swfBridge = Loader(mx_internal::contentHolder).contentLoaderInfo.sharedEvents;
  574.             _loc3_ = systemManager;
  575.             _loc3_.addChildBridge(_swfBridge,this);
  576.             removeInitSystemManagerCompleteListener(Loader(mx_internal::contentHolder).contentLoaderInfo);
  577.             _swfBridge.addEventListener(SWFBridgeRequest.INVALIDATE_REQUEST,invalidateRequestHandler);
  578.          }
  579.       }
  580.       
  581.       [Bindable("complete")]
  582.       public function get bytesTotal() : Number
  583.       {
  584.          return _bytesTotal;
  585.       }
  586.       
  587.       private function initializeHandler(param1:FlexEvent) : void
  588.       {
  589.          if(contentChanged)
  590.          {
  591.             contentChanged = false;
  592.             if(_autoLoad)
  593.             {
  594.                load(_source);
  595.             }
  596.          }
  597.       }
  598.       
  599.       private function contentLoaderInfo_unloadEventHandler(param1:Event) : void
  600.       {
  601.          var _loc2_:ISystemManager = null;
  602.          dispatchEvent(param1);
  603.          if(_swfBridge)
  604.          {
  605.             _swfBridge.removeEventListener(SWFBridgeRequest.INVALIDATE_REQUEST,invalidateRequestHandler);
  606.             _loc2_ = systemManager;
  607.             _loc2_.removeChildBridge(_swfBridge);
  608.             _swfBridge = null;
  609.          }
  610.          if(mx_internal::contentHolder is Loader)
  611.          {
  612.             removeInitSystemManagerCompleteListener(Loader(mx_internal::contentHolder).contentLoaderInfo);
  613.          }
  614.       }
  615.       
  616.       mx_internal function contentLoaderInfo_completeEventHandler(param1:Event) : void
  617.       {
  618.          if(LoaderInfo(param1.target).loader != mx_internal::contentHolder)
  619.          {
  620.             return;
  621.          }
  622.          dispatchEvent(param1);
  623.          contentLoaded();
  624.          if(mx_internal::contentHolder is Loader)
  625.          {
  626.             removeInitSystemManagerCompleteListener(Loader(mx_internal::contentHolder).contentLoaderInfo);
  627.          }
  628.       }
  629.       
  630.       public function set scaleContent(param1:Boolean) : void
  631.       {
  632.          if(_scaleContent != param1)
  633.          {
  634.             _scaleContent = param1;
  635.             scaleContentChanged = true;
  636.             invalidateDisplayList();
  637.          }
  638.          dispatchEvent(new Event("scaleContentChanged"));
  639.       }
  640.       
  641.       private function contentLoaderInfo_openEventHandler(param1:Event) : void
  642.       {
  643.          dispatchEvent(param1);
  644.       }
  645.       
  646.       private function addedToStageHandler(param1:Event) : void
  647.       {
  648.          systemManager.getSandboxRoot().addEventListener(InterManagerRequest.DRAG_MANAGER_REQUEST,mouseShieldHandler,false,0,true);
  649.       }
  650.       
  651.       [Bindable("progress")]
  652.       public function get percentLoaded() : Number
  653.       {
  654.          var _loc1_:Number = isNaN(_bytesTotal) || _bytesTotal == 0 ? 0 : 100 * (_bytesLoaded / _bytesTotal);
  655.          if(isNaN(_loc1_))
  656.          {
  657.             _loc1_ = 0;
  658.          }
  659.          return _loc1_;
  660.       }
  661.       
  662.       public function get swfBridge() : IEventDispatcher
  663.       {
  664.          return _swfBridge;
  665.       }
  666.       
  667.       private function loadContent(param1:Object) : DisplayObject
  668.       {
  669.          var child:DisplayObject = null;
  670.          var cls:Class = null;
  671.          var url:String = null;
  672.          var byteArray:ByteArray = null;
  673.          var loader:Loader = null;
  674.          var lc:LoaderContext = null;
  675.          var rootURL:String = null;
  676.          var lastIndex:int = 0;
  677.          var currentDomain:ApplicationDomain = null;
  678.          var topmostDomain:ApplicationDomain = null;
  679.          var message:String = null;
  680.          var classOrString:Object = param1;
  681.          if(classOrString is Class)
  682.          {
  683.             cls = Class(classOrString);
  684.          }
  685.          else if(classOrString is String)
  686.          {
  687.             try
  688.             {
  689.                cls = Class(systemManager.getDefinitionByName(String(classOrString)));
  690.             }
  691.             catch(e:Error)
  692.             {
  693.             }
  694.             url = String(classOrString);
  695.          }
  696.          else if(classOrString is ByteArray)
  697.          {
  698.             byteArray = ByteArray(classOrString);
  699.          }
  700.          else
  701.          {
  702.             url = classOrString.toString();
  703.          }
  704.          if(cls)
  705.          {
  706.             mx_internal::contentHolder = child = new cls();
  707.             addChild(child);
  708.             contentLoaded();
  709.          }
  710.          else if(classOrString is DisplayObject)
  711.          {
  712.             mx_internal::contentHolder = child = DisplayObject(classOrString);
  713.             addChild(child);
  714.             contentLoaded();
  715.          }
  716.          else if(byteArray)
  717.          {
  718.             loader = new FlexLoader();
  719.             child = loader;
  720.             addChild(child);
  721.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE,mx_internal::contentLoaderInfo_completeEventHandler);
  722.             loader.contentLoaderInfo.addEventListener(Event.INIT,contentLoaderInfo_initEventHandler);
  723.             loader.contentLoaderInfo.addEventListener(Event.UNLOAD,contentLoaderInfo_unloadEventHandler);
  724.             loader.loadBytes(byteArray,loaderContext);
  725.          }
  726.          else
  727.          {
  728.             if(!url)
  729.             {
  730.                message = resourceManager.getString("controls","notLoadable",[source]);
  731.                throw new Error(message);
  732.             }
  733.             loader = new FlexLoader();
  734.             child = loader;
  735.             addChild(loader);
  736.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE,mx_internal::contentLoaderInfo_completeEventHandler);
  737.             loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS,contentLoaderInfo_httpStatusEventHandler);
  738.             loader.contentLoaderInfo.addEventListener(Event.INIT,contentLoaderInfo_initEventHandler);
  739.             loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,contentLoaderInfo_ioErrorEventHandler);
  740.             loader.contentLoaderInfo.addEventListener(Event.OPEN,contentLoaderInfo_openEventHandler);
  741.             loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,contentLoaderInfo_progressEventHandler);
  742.             loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,contentLoaderInfo_securityErrorEventHandler);
  743.             loader.contentLoaderInfo.addEventListener(Event.UNLOAD,contentLoaderInfo_unloadEventHandler);
  744.             if(Capabilities.isDebugger == true && url.indexOf(".jpg") == -1 && LoaderUtil.normalizeURL(Application.application.systemManager.loaderInfo).indexOf("debug=true") > -1)
  745.             {
  746.                url += url.indexOf("?") > -1 ? "&debug=true" : "?debug=true";
  747.             }
  748.             if(!(url.indexOf(":") > -1 || url.indexOf("/") == 0 || url.indexOf("\\") == 0))
  749.             {
  750.                if(SystemManagerGlobals.bootstrapLoaderInfoURL != null && SystemManagerGlobals.bootstrapLoaderInfoURL != "")
  751.                {
  752.                   rootURL = SystemManagerGlobals.bootstrapLoaderInfoURL;
  753.                }
  754.                else if(root)
  755.                {
  756.                   rootURL = LoaderUtil.normalizeURL(root.loaderInfo);
  757.                }
  758.                else if(systemManager)
  759.                {
  760.                   rootURL = LoaderUtil.normalizeURL(DisplayObject(systemManager).loaderInfo);
  761.                }
  762.                if(rootURL)
  763.                {
  764.                   lastIndex = Math.max(rootURL.lastIndexOf("\\"),rootURL.lastIndexOf("/"));
  765.                   if(lastIndex != -1)
  766.                   {
  767.                      url = rootURL.substr(0,lastIndex + 1) + url;
  768.                   }
  769.                }
  770.             }
  771.             requestedURL = new URLRequest(url);
  772.             lc = loaderContext;
  773.             if(!lc)
  774.             {
  775.                lc = new LoaderContext();
  776.                _loaderContext = lc;
  777.                if(loadForCompatibility)
  778.                {
  779.                   currentDomain = ApplicationDomain.currentDomain.parentDomain;
  780.                   topmostDomain = null;
  781.                   while(currentDomain)
  782.                   {
  783.                      topmostDomain = currentDomain;
  784.                      currentDomain = currentDomain.parentDomain;
  785.                   }
  786.                   lc.applicationDomain = new ApplicationDomain(topmostDomain);
  787.                }
  788.                if(trustContent)
  789.                {
  790.                   lc.securityDomain = SecurityDomain.currentDomain;
  791.                }
  792.                else if(!loadForCompatibility)
  793.                {
  794.                   attemptingChildAppDomain = true;
  795.                   lc.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
  796.                }
  797.             }
  798.             loader.load(requestedURL,lc);
  799.          }
  800.          invalidateDisplayList();
  801.          return child;
  802.       }
  803.       
  804.       public function get contentWidth() : Number
  805.       {
  806.          return !!mx_internal::contentHolder ? mx_internal::contentHolder.width : NaN;
  807.       }
  808.       
  809.       [Bindable("scaleContentChanged")]
  810.       public function get scaleContent() : Boolean
  811.       {
  812.          return _scaleContent;
  813.       }
  814.       
  815.       public function get childAllowsParent() : Boolean
  816.       {
  817.          if(!isContentLoaded)
  818.          {
  819.             return false;
  820.          }
  821.          if(mx_internal::contentHolder is Loader)
  822.          {
  823.             return Loader(mx_internal::contentHolder).contentLoaderInfo.childAllowsParent;
  824.          }
  825.          return true;
  826.       }
  827.       
  828.       override protected function commitProperties() : void
  829.       {
  830.          super.commitProperties();
  831.          if(contentChanged)
  832.          {
  833.             contentChanged = false;
  834.             if(_autoLoad)
  835.             {
  836.                load(_source);
  837.             }
  838.          }
  839.       }
  840.       
  841.       private function contentLoaderInfo_securityErrorEventHandler(param1:SecurityErrorEvent) : void
  842.       {
  843.          var _loc2_:LoaderContext = null;
  844.          if(attemptingChildAppDomain)
  845.          {
  846.             attemptingChildAppDomain = false;
  847.             _loc2_ = new LoaderContext();
  848.             _loaderContext = _loc2_;
  849.             callLater(load);
  850.             return;
  851.          }
  852.          dispatchEvent(param1);
  853.          if(mx_internal::contentHolder is Loader)
  854.          {
  855.             removeInitSystemManagerCompleteListener(Loader(mx_internal::contentHolder).contentLoaderInfo);
  856.          }
  857.       }
  858.       
  859.       private function sizeShield() : void
  860.       {
  861.          if(Boolean(mouseShield) && Boolean(mouseShield.parent))
  862.          {
  863.             mouseShield.width = unscaledWidth;
  864.             mouseShield.height = unscaledHeight;
  865.          }
  866.       }
  867.       
  868.       private function addInitSystemManagerCompleteListener(param1:LoaderInfo) : void
  869.       {
  870.          var _loc2_:EventDispatcher = null;
  871.          if(param1.contentType == "application/x-shockwave-flash")
  872.          {
  873.             _loc2_ = param1.sharedEvents;
  874.             _loc2_.addEventListener(SWFBridgeEvent.BRIDGE_NEW_APPLICATION,initSystemManagerCompleteEventHandler);
  875.          }
  876.       }
  877.       
  878.       private function invalidateRequestHandler(param1:Event) : void
  879.       {
  880.          if(param1 is SWFBridgeRequest)
  881.          {
  882.             return;
  883.          }
  884.          var _loc2_:SWFBridgeRequest = SWFBridgeRequest.marshal(param1);
  885.          var _loc3_:uint = uint(_loc2_.data);
  886.          if(_loc3_ & InvalidateRequestData.PROPERTIES)
  887.          {
  888.             invalidateProperties();
  889.          }
  890.          if(_loc3_ & InvalidateRequestData.SIZE)
  891.          {
  892.             invalidateSize();
  893.          }
  894.          if(_loc3_ & InvalidateRequestData.DISPLAY_LIST)
  895.          {
  896.             invalidateDisplayList();
  897.          }
  898.          dispatchInvalidateRequest((_loc3_ & InvalidateRequestData.PROPERTIES) != 0,(_loc3_ & InvalidateRequestData.SIZE) != 0,(_loc3_ & InvalidateRequestData.DISPLAY_LIST) != 0);
  899.       }
  900.       
  901.       private function contentLoaded() : void
  902.       {
  903.          var loaderInfo:LoaderInfo = null;
  904.          isContentLoaded = true;
  905.          if(mx_internal::contentHolder is Loader)
  906.          {
  907.             loaderInfo = Loader(mx_internal::contentHolder).contentLoaderInfo;
  908.          }
  909.          resizableContent = false;
  910.          if(loaderInfo)
  911.          {
  912.             if(loaderInfo.contentType == "application/x-shockwave-flash")
  913.             {
  914.                resizableContent = true;
  915.             }
  916.             if(resizableContent)
  917.             {
  918.                try
  919.                {
  920.                   if(Loader(mx_internal::contentHolder).content is IFlexDisplayObject)
  921.                   {
  922.                      flexContent = true;
  923.                   }
  924.                   else
  925.                   {
  926.                      flexContent = swfBridge != null;
  927.                   }
  928.                }
  929.                catch(e:Error)
  930.                {
  931.                   flexContent = swfBridge != null;
  932.                }
  933.             }
  934.          }
  935.          try
  936.          {
  937.             if(tabChildren && mx_internal::contentHolder is Loader && (loaderInfo.contentType == "application/x-shockwave-flash" || Loader(mx_internal::contentHolder).content is DisplayObjectContainer))
  938.             {
  939.                Loader(mx_internal::contentHolder).tabChildren = true;
  940.                DisplayObjectContainer(Loader(mx_internal::contentHolder).content).tabChildren = true;
  941.             }
  942.          }
  943.          catch(e:Error)
  944.          {
  945.          }
  946.          invalidateSize();
  947.          invalidateDisplayList();
  948.       }
  949.       
  950.       private function getContentSize() : Point
  951.       {
  952.          var _loc3_:IEventDispatcher = null;
  953.          var _loc4_:SWFBridgeRequest = null;
  954.          var _loc1_:Point = new Point();
  955.          if(!mx_internal::contentHolder is Loader)
  956.          {
  957.             return _loc1_;
  958.          }
  959.          var _loc2_:Loader = Loader(mx_internal::contentHolder);
  960.          if(_loc2_.contentLoaderInfo.childAllowsParent)
  961.          {
  962.             _loc1_.x = _loc2_.content.width;
  963.             _loc1_.y = _loc2_.content.height;
  964.          }
  965.          else
  966.          {
  967.             _loc3_ = swfBridge;
  968.             if(_loc3_)
  969.             {
  970.                _loc4_ = new SWFBridgeRequest(SWFBridgeRequest.GET_SIZE_REQUEST);
  971.                _loc3_.dispatchEvent(_loc4_);
  972.                _loc1_.x = _loc4_.data.width;
  973.                _loc1_.y = _loc4_.data.height;
  974.             }
  975.          }
  976.          if(_loc1_.x == 0)
  977.          {
  978.             _loc1_.x = _loc2_.contentLoaderInfo.width;
  979.          }
  980.          if(_loc1_.y == 0)
  981.          {
  982.             _loc1_.y = _loc2_.contentLoaderInfo.height;
  983.          }
  984.          return _loc1_;
  985.       }
  986.       
  987.       public function load(param1:Object = null) : void
  988.       {
  989.          var imageData:Bitmap = null;
  990.          var request:SWFBridgeEvent = null;
  991.          var url:Object = param1;
  992.          if(url)
  993.          {
  994.             _source = url;
  995.          }
  996.          if(mx_internal::contentHolder)
  997.          {
  998.             if(isContentLoaded)
  999.             {
  1000.                if(mx_internal::contentHolder is Loader)
  1001.                {
  1002.                   try
  1003.                   {
  1004.                      if(Loader(mx_internal::contentHolder).content is Bitmap)
  1005.                      {
  1006.                         imageData = Bitmap(Loader(mx_internal::contentHolder).content);
  1007.                         if(imageData.bitmapData)
  1008.                         {
  1009.                            imageData.bitmapData = null;
  1010.                         }
  1011.                      }
  1012.                   }
  1013.                   catch(error:Error)
  1014.                   {
  1015.                   }
  1016.                   if(_swfBridge)
  1017.                   {
  1018.                      request = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_APPLICATION_UNLOADING,false,false,_swfBridge);
  1019.                      _swfBridge.dispatchEvent(request);
  1020.                   }
  1021.                   if(useUnloadAndStop && "unloadAndStop" in mx_internal::contentHolder)
  1022.                   {
  1023.                      mx_internal::contentHolder["unloadAndStop"](unloadAndStopGC);
  1024.                   }
  1025.                   else
  1026.                   {
  1027.                      Loader(mx_internal::contentHolder).unload();
  1028.                   }
  1029.                   if(!explicitLoaderContext)
  1030.                   {
  1031.                      _loaderContext = null;
  1032.                   }
  1033.                }
  1034.                else if(mx_internal::contentHolder is Bitmap)
  1035.                {
  1036.                   imageData = Bitmap(mx_internal::contentHolder);
  1037.                   if(imageData.bitmapData)
  1038.                   {
  1039.                      imageData.bitmapData = null;
  1040.                   }
  1041.                }
  1042.             }
  1043.             else if(mx_internal::contentHolder is Loader)
  1044.             {
  1045.                try
  1046.                {
  1047.                   Loader(mx_internal::contentHolder).close();
  1048.                }
  1049.                catch(error:Error)
  1050.                {
  1051.                }
  1052.             }
  1053.             try
  1054.             {
  1055.                if(mx_internal::contentHolder.parent == this)
  1056.                {
  1057.                   removeChild(mx_internal::contentHolder);
  1058.                }
  1059.             }
  1060.             catch(error:Error)
  1061.             {
  1062.                try
  1063.                {
  1064.                   removeChild(mx_internal::contentHolder);
  1065.                }
  1066.                catch(error1:Error)
  1067.                {
  1068.                }
  1069.             }
  1070.             mx_internal::contentHolder = null;
  1071.          }
  1072.          isContentLoaded = false;
  1073.          brokenImage = false;
  1074.          useUnloadAndStop = false;
  1075.          if(!_source || _source == "")
  1076.          {
  1077.             return;
  1078.          }
  1079.          mx_internal::contentHolder = loadContent(_source);
  1080.       }
  1081.       
  1082.       public function get parentAllowsChild() : Boolean
  1083.       {
  1084.          if(!isContentLoaded)
  1085.          {
  1086.             return false;
  1087.          }
  1088.          if(mx_internal::contentHolder is Loader)
  1089.          {
  1090.             return Loader(mx_internal::contentHolder).contentLoaderInfo.parentAllowsChild;
  1091.          }
  1092.          return true;
  1093.       }
  1094.       
  1095.       private function contentLoaderInfo_ioErrorEventHandler(param1:IOErrorEvent) : void
  1096.       {
  1097.          source = getStyle("brokenImageSkin");
  1098.          load();
  1099.          contentChanged = false;
  1100.          brokenImage = true;
  1101.          if(hasEventListener(param1.type))
  1102.          {
  1103.             dispatchEvent(param1);
  1104.          }
  1105.          if(mx_internal::contentHolder is Loader)
  1106.          {
  1107.             removeInitSystemManagerCompleteListener(Loader(mx_internal::contentHolder).contentLoaderInfo);
  1108.          }
  1109.       }
  1110.       
  1111.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  1112.       {
  1113.          var _loc3_:Class = null;
  1114.          super.updateDisplayList(param1,param2);
  1115.          if(contentChanged)
  1116.          {
  1117.             contentChanged = false;
  1118.             if(_autoLoad)
  1119.             {
  1120.                load(_source);
  1121.             }
  1122.          }
  1123.          if(isContentLoaded)
  1124.          {
  1125.             if(_scaleContent && !brokenImage)
  1126.             {
  1127.                doScaleContent();
  1128.             }
  1129.             else
  1130.             {
  1131.                doScaleLoader();
  1132.             }
  1133.             scaleContentChanged = false;
  1134.          }
  1135.          if(brokenImage && !brokenImageBorder)
  1136.          {
  1137.             _loc3_ = getStyle("brokenImageBorderSkin");
  1138.             if(_loc3_)
  1139.             {
  1140.                brokenImageBorder = IFlexDisplayObject(new _loc3_());
  1141.                if(brokenImageBorder is ISimpleStyleClient)
  1142.                {
  1143.                   ISimpleStyleClient(brokenImageBorder).styleName = this;
  1144.                }
  1145.                addChild(DisplayObject(brokenImageBorder));
  1146.             }
  1147.          }
  1148.          else if(!brokenImage && Boolean(brokenImageBorder))
  1149.          {
  1150.             removeChild(DisplayObject(brokenImageBorder));
  1151.             brokenImageBorder = null;
  1152.          }
  1153.          if(brokenImageBorder)
  1154.          {
  1155.             brokenImageBorder.setActualSize(param1,param2);
  1156.          }
  1157.          sizeShield();
  1158.       }
  1159.       
  1160.       private function doScaleContent() : void
  1161.       {
  1162.          var interiorWidth:Number = NaN;
  1163.          var interiorHeight:Number = NaN;
  1164.          var contentWidth:Number = NaN;
  1165.          var contentHeight:Number = NaN;
  1166.          var x:Number = NaN;
  1167.          var y:Number = NaN;
  1168.          var newXScale:Number = NaN;
  1169.          var newYScale:Number = NaN;
  1170.          var scale:Number = NaN;
  1171.          var w:Number = NaN;
  1172.          var h:Number = NaN;
  1173.          var holder:Loader = null;
  1174.          var sizeSet:Boolean = false;
  1175.          var lInfo:LoaderInfo = null;
  1176.          if(!isContentLoaded)
  1177.          {
  1178.             return;
  1179.          }
  1180.          if(!resizableContent || maintainAspectRatio && !flexContent)
  1181.          {
  1182.             unScaleContent();
  1183.             interiorWidth = unscaledWidth;
  1184.             interiorHeight = unscaledHeight;
  1185.             contentWidth = contentHolderWidth;
  1186.             contentHeight = contentHolderHeight;
  1187.             x = 0;
  1188.             y = 0;
  1189.             newXScale = contentWidth == 0 ? 1 : interiorWidth / contentWidth;
  1190.             newYScale = contentHeight == 0 ? 1 : interiorHeight / contentHeight;
  1191.             if(_maintainAspectRatio)
  1192.             {
  1193.                if(newXScale > newYScale)
  1194.                {
  1195.                   x = Math.floor((interiorWidth - contentWidth * newYScale) * getHorizontalAlignValue());
  1196.                   scale = newYScale;
  1197.                }
  1198.                else
  1199.                {
  1200.                   y = Math.floor((interiorHeight - contentHeight * newXScale) * getVerticalAlignValue());
  1201.                   scale = newXScale;
  1202.                }
  1203.                mx_internal::contentHolder.scaleX = scale;
  1204.                mx_internal::contentHolder.scaleY = scale;
  1205.             }
  1206.             else
  1207.             {
  1208.                mx_internal::contentHolder.scaleX = newXScale;
  1209.                mx_internal::contentHolder.scaleY = newYScale;
  1210.             }
  1211.             mx_internal::contentHolder.x = x;
  1212.             mx_internal::contentHolder.y = y;
  1213.          }
  1214.          else
  1215.          {
  1216.             mx_internal::contentHolder.x = 0;
  1217.             mx_internal::contentHolder.y = 0;
  1218.             w = unscaledWidth;
  1219.             h = unscaledHeight;
  1220.             if(mx_internal::contentHolder is Loader)
  1221.             {
  1222.                holder = Loader(mx_internal::contentHolder);
  1223.                try
  1224.                {
  1225.                   if(getContentSize().x > 0)
  1226.                   {
  1227.                      sizeSet = false;
  1228.                      if(holder.contentLoaderInfo.contentType == "application/x-shockwave-flash")
  1229.                      {
  1230.                         if(childAllowsParent)
  1231.                         {
  1232.                            if(holder.content is IFlexDisplayObject)
  1233.                            {
  1234.                               IFlexDisplayObject(holder.content).setActualSize(w,h);
  1235.                               sizeSet = true;
  1236.                            }
  1237.                         }
  1238.                         if(!sizeSet)
  1239.                         {
  1240.                            if(swfBridge)
  1241.                            {
  1242.                               swfBridge.dispatchEvent(new SWFBridgeRequest(SWFBridgeRequest.SET_ACTUAL_SIZE_REQUEST,false,false,null,{
  1243.                                  "width":w,
  1244.                                  "height":h
  1245.                               }));
  1246.                               sizeSet = true;
  1247.                            }
  1248.                         }
  1249.                      }
  1250.                      else
  1251.                      {
  1252.                         lInfo = holder.contentLoaderInfo;
  1253.                         if(lInfo)
  1254.                         {
  1255.                            mx_internal::contentHolder.scaleX = w / lInfo.width;
  1256.                            mx_internal::contentHolder.scaleY = h / lInfo.height;
  1257.                            sizeSet = true;
  1258.                         }
  1259.                      }
  1260.                      if(!sizeSet)
  1261.                      {
  1262.                         mx_internal::contentHolder.width = w;
  1263.                         mx_internal::contentHolder.height = h;
  1264.                      }
  1265.                   }
  1266.                   else if(childAllowsParent && !(holder.content is IFlexDisplayObject))
  1267.                   {
  1268.                      mx_internal::contentHolder.width = w;
  1269.                      mx_internal::contentHolder.height = h;
  1270.                   }
  1271.                }
  1272.                catch(error:Error)
  1273.                {
  1274.                   mx_internal::contentHolder.width = w;
  1275.                   mx_internal::contentHolder.height = h;
  1276.                }
  1277.                if(!parentAllowsChild)
  1278.                {
  1279.                   mx_internal::contentHolder.scrollRect = new Rectangle(0,0,w / mx_internal::contentHolder.scaleX,h / mx_internal::contentHolder.scaleY);
  1280.                }
  1281.             }
  1282.             else
  1283.             {
  1284.                mx_internal::contentHolder.width = w;
  1285.                mx_internal::contentHolder.height = h;
  1286.             }
  1287.          }
  1288.       }
  1289.       
  1290.       private function mouseShieldHandler(param1:Event) : void
  1291.       {
  1292.          if(param1["name"] != "mouseShield")
  1293.          {
  1294.             return;
  1295.          }
  1296.          if(parentAllowsChild)
  1297.          {
  1298.             return;
  1299.          }
  1300.          if(param1["value"])
  1301.          {
  1302.             if(!mouseShield)
  1303.             {
  1304.                mouseShield = new Sprite();
  1305.                mouseShield.graphics.beginFill(0,0);
  1306.                mouseShield.graphics.drawRect(0,0,100,100);
  1307.                mouseShield.graphics.endFill();
  1308.             }
  1309.             if(!mouseShield.parent)
  1310.             {
  1311.                addChild(mouseShield);
  1312.             }
  1313.             sizeShield();
  1314.          }
  1315.          else if(Boolean(mouseShield) && Boolean(mouseShield.parent))
  1316.          {
  1317.             removeChild(mouseShield);
  1318.          }
  1319.       }
  1320.    }
  1321. }
  1322.  
  1323.